<template>
	<div id="app">
		<el-backtop></el-backtop>
		<keep-alive :exclude="['MyCenter','Detail']">
			<router-view></router-view>
		</keep-alive>

	</div>
</template>

<script>
    import storage from './model/storage.js';
	export default {
		name: 'app',
		data() {
			return {
				msg: '你是谁'
			}
		},
		methods: {
		    //根组件挂载时从服务器获取用户信息
		    getUserInfo(){
                console.log("根组件挂载调用");
                if (sessionStorage.getItem("userInfo") !== null && sessionStorage.getItem("userInfo") !== undefined) {
                    this.$store.commit("updateIsLogin", true);
                    this.$store.commit("updateUserInfo", storage.getSession("userInfo"));
                }else{
                    this.$axios.get('/getUserInfoBySession')
                        .then((response) => {
                            if(response.data.success){
                                storage.setSession("userInfo", response.data.data);
                                this.$store.commit("updateIsLogin", true);
                                this.$store.commit("updateUserInfo", response.data.data);
                            }else{
                                console.log("未登陆过或者session过期。");
                            }
                        })
                        .catch((error) => {
                            console.log(error);
                        });
                }
            }
		},
		components:{
		},
        mounted() {
		    //组件挂载时获取用户信息
            this.getUserInfo();
        }
    }
</script>

<style>
	body{
		margin: 0;
		padding: 0;
		border: 0;
	}
	html{
		font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
		background-color: #f0f0f0;
	}
	/* 滚动条宽度 */
	::-webkit-scrollbar {
		width: 5px;
		height: 8px;
	}
	/* 滚动条的滑块 */
	::-webkit-scrollbar-thumb {
		background-color: #a1a3a9;
		border-radius: 2px;
	}
</style>
